package com.maomao.test.io;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

/**
 *
 * @author admin
 * @date 2018/4/23
 */
public class UsingRandomAccessFile {
    static String file = "C:\\Users\\admin\\Desktop\\selfFile\\test3.txt";
    static void display() throws IOException {
        RandomAccessFile rf = new RandomAccessFile(file,"r");
        for (int i= 0; i<7;i++) {
            System.out.println("Value" +i+":"+rf.readDouble());
        }
        System.out.println(rf.readDouble());
        rf.close();
    }
    public static void main(String[] args) throws IOException {
        RandomAccessFile rf = new RandomAccessFile(file,"rw");
        for (int i = 0;i<7;i++) {
            rf.writeDouble(i*1.414);
        }
        rf.writeUTF("The end of the file");
        rf.close();
        display();
        rf = new RandomAccessFile(file,"rw");
        rf.seek(5*8);
        rf.writeDouble(47*0001);
        rf.close();
        display();
    }
}
